RWTH - Mindstorms NXT Toolbox

NXT_GetInputValues

Processes a complete sensor reading, i.e. requests input values and collects the answer.

Contents

Syntax

data = NXT_GetInputValues(port)

data = NXT_GetInputValues(port, handle)

Description

data = NXT_GetInputValues(port) processes a complete sensor reading, i.e. requests input values and collects the answer of the given sensor port. The value port can be addressed by the symbolic constants SENSOR_1, SENSOR_2, SENSOR_3 and SENSOR_4 analog to the labeling on the NXT Brick. The return value data is a struct variable. It contains several sensor settings and information.

data = NXT_GetInputValues(port, handle) uses the given Bluetooth connection handle. This should be a serial handle on a PC system and a file handle on a Linux system.

If no Bluetooth handle is specified the default one (COM_GetDefaultNXT) is used.

Output:

data.Port % current port number (0..3)

data.Valid % validation flag

data.Calibrated % boolean, true if calibration file found and used

data.TypeByte % sensor type

data.TypeName % sensor mode

data.ModeByte % mode

data.ModeName % mode name

data.RawADVal % raw A/D value

data.NormalizedADVal % normalized A/D value

data.ScaledVal % scaled value

data.CalibratedVal % calibrated value

Note:

Data are only valid if .Valid is ~= 0. This should usually be the case, but a short while after setting a new sensor mode using NXT_SetInputMode, you have to carefully check .Valid on your own! Experience shows that only .ScaledVal is influenced by this, apparently .NormalizedADVal seems valid all the time, but closer examination is needed...

For more details see the official LEGO Mindstorms communication protocol.

Examples

   data = NXT_GetInputValues(SENSOR_3);
   handle = COM_OpenNXT('bluetooth.ini','check');
   data = NXT_GetInputValues(SENSOR_1, handle);

See also

NXT_SetInputMode, GetLight, GetSwitch, GetSound, GetUltrasonic, SENSOR_1, SENSOR_2, SENSOR_3, SENSOR_4

Signature